package com.pfsoft.security.self;

import java.nio.charset.StandardCharsets;

/**
 * @author pengfei
 * @date 2022年07月26日 10:53
 * 自己实现凯撒算法
 */

public class CeasarSecurityUtil {

    public String encrypt(String text) {
        char[] chars = text.toCharArray();
        char[] pwdChars = new char[chars.length];
        for (int i = 0; i < chars.length; i++) {
            char tmp = (char) (chars[i] + 3);
            pwdChars[i] = tmp;
        }
        return  new String(pwdChars);
    }


    public String decrypt(String pwd) {
        char[] pwdChars = pwd.toCharArray();
        char[] chars = new char[pwdChars.length];
        for (int i = 0; i < pwdChars.length; i++) {
            chars[i] = (char) (pwdChars[i] - 3 );
        }
        return  new String(chars);
    }
}
